home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.015.CDev.Samples / Pascal / CDev.p next >
Encoding:
Text File  |  1990-06-24  |  7.3 KB  |  212 lines  |  [TEXT/MPS ]

  1. {############################################################}
  2. {#                                                            #}
  3. {#    File:            CDev.p                                    #}
  4. {#    Version:        3.0                                        #}
  5. {#    Author:                                                    #}
  6. {#    Copyright:        (c) 1989-1990 by Apple Computer, Inc.    #}
  7. {#    Developer Technical Support Apple II Sample Code        #}
  8. {#                                                            #}
  9. {#    Description:    This file contains the cdev pascal        #}
  10. {#                    routine used by the Shell CDEV.            #}
  11. {#                                                            #}
  12. {#----------------------------------------------------------#}
  13. {#                                                            #}
  14. {#    Development History:                                    #}
  15. {#                                                            #}
  16. {#    Who        Date        The Modification                    #}
  17. {#    ---        --------    ----------------                    #}
  18. {#                                                            #}
  19. {############################################################}
  20.  
  21. {$R-}
  22.  
  23. unit CDev;
  24.  
  25. interface
  26.  
  27. uses
  28.     Types,
  29.     GSOS,
  30.     Quickdraw,
  31.     Fonts,
  32.     Memory,
  33.     IntMath,
  34.     Events,
  35.     ProDOS,
  36.     Locator,
  37.     Controls,
  38.     Windows,
  39.     Lists,
  40.     Scrap,
  41.     Dialogs,
  42.     Menus,
  43.     Desk,
  44.     StdFile,
  45.     QDAUX,
  46.     Print,
  47.     MiscTool,
  48.     LineEdit,
  49.     Resources,
  50.     CDEVIntF;
  51.  
  52. {############################################################}
  53. {#        Define the CDEV constants/types,vars                #}
  54. {############################################################}
  55.  
  56. function MyCDEV(message : integer; data1, data2 : LongInt) : LongInt;
  57.  
  58. implementation
  59.  
  60. {############################################################}
  61. {#        Actual CDEV, this is called by the control panel    #}
  62. {############################################################}
  63.  
  64. const
  65.     AboutID    =    $1000;
  66.     PopUpList =    $5000;
  67.     PopUp1    =    $5001;
  68.     PopUp2    =    $5002;
  69.     PopUp3    =    $5003;
  70.     PopUp1Item1 = $5101;
  71.     PopUp2Item1 = $5201;
  72.     PopUp3Item1 = $5301;
  73.  
  74. { This routine is eventually linked and then placed into a cdev code resource.
  75.   The only requirements are that this routine is at the beginning of the resource
  76.   so if the CDEV has any other routines they must follow this one.  The cdev's resource
  77.   fork is always opened when a call to the cdev is made.  The cdev can also assume
  78.   that the current port is set to the ctl panel window except in the boot message,
  79.   where quickdraw isn't even started, and in the about message, where it is the port
  80.   of the help window.  All normal managers will be stared up for all calls except
  81.   the boot call, which will only have miscTools & Resource Manager started. }
  82.  
  83. function myCDEV(message : integer; data1, data2 : longint) : longint;
  84.  
  85.     var
  86.         tempCtl : CtlRecHndl;
  87.     
  88.     begin    { this will only get called when a ctl is hit }
  89.         MyCDEV := 0;    { initialize the function result to zero, so that we will work in
  90.                             future versions of the Control Panel! }
  91.  
  92.         case message of
  93.             BootCDEV:
  94.                 begin
  95.                     { If the wantBoot flag is set, this routine will be called during the
  96.                       startup sequence.  The control panel takes care of drawing the "boot"
  97.                       icon.  When this call is made, the machine state is bad at best.
  98.                       QuickDraw is not even started up.  The parameters to this call are
  99.                       undefined. }
  100.                 end;
  101.  
  102.             MachineCDEV:
  103.                 begin
  104.                     { This is called if the wantMachine bit is set in the CDEV flags.
  105.                       It enables the CDEV to do further checking to see if it makes
  106.                       sense for the CDEV to be visible to the user or not.  For instance,
  107.                       if the CDEV controls a setting for some hardware, we could check to
  108.                       see if the hardware is really connected.  The parameters are undefined
  109.                       for this call and the result is passed back as the function result.  0 =
  110.                       don't show this CDEV, <>0 = show this CDEV.  The control panel will do
  111.                       some machine checking even before calling this routine by checking the
  112.                       ROM version number against the machine field of the cdev flags resource }
  113.                 end;
  114.  
  115.             CreateCDEV:
  116.                 begin
  117.                     { If the wantCreate bit is set, this message is called with the control
  118.                       panel's window ptr passed in data1.  The cdev must create any controls
  119.                       it has during this call.  The CDEV's resource fork is open during this
  120.                       call so resource manager calls can be made.  All controls rectangles
  121.                       MUST be relative to 0,0.  The control panel handles offsetting controls
  122.                       to the proper place in the window.  Initialization of the controls
  123.                       needs to be done in the InitCDEV call.  Just create the controls in this
  124.                       call. }
  125.                     
  126.                     tempCtl := NewControl2(WindowPtr(data1),9,Ref(PopUpList));
  127.                 end;
  128.  
  129.             InitCDEV:
  130.                 begin
  131.                     { If the wantInit flag is set, then this message is passed with data1 =
  132.                       the control panel's window ptr.  By  this time the CreateCDEV call
  133.                       will have been made and thus the controls used by the CDEV created.
  134.                       This call enables the CDEV to initialize the controls before they are
  135.                       displayed. }
  136.                     
  137.                     SetCtlValue(PopUp1Item1, GetCtlHandleFromID(WindowPtr(data1), PopUp1));
  138.                     SetCtlValue(PopUp2Item1, GetCtlHandleFromID(WindowPtr(data1), PopUp2));
  139.                     SetCtlValue(PopUp3Item1, GetCtlHandleFromID(WindowPtr(data1), PopUp3));
  140.                 end;
  141.  
  142.             AboutCDEV:
  143.                 begin
  144.                     { If the wantAbout bit is set in the CDEV flags, this call is made when
  145.                       the user selects help.  Data1 = window ptr to the help window.  The
  146.                       control panel automatically handles the icon, author, and version #
  147.                       display.}
  148.                     
  149.                     tempCtl := NewControl2(WindowPtr(data1),2,Ref(AboutID));
  150.                 end;
  151.  
  152.             RectCDEV:
  153.                 begin
  154.                     { If a CDEV has a different size data rectangle depending on some state,
  155.                       like the printer & modem port cdev's, then you can get a chance to tell the
  156.                       control panel this by setting the wantRect bit in the CDEV flags.  In
  157.                       this call, data1 is a ptr to the rect and can be directly modified by
  158.                       the CDEV. }
  159.                 end;
  160.  
  161.             EventsCDEV:
  162.                 begin
  163.                     { If the wantEvents bit is set, the control panel will call this routine
  164.                       with data1 = ptr to the event record.  This allows the cdev to intercept
  165.                       and even *gasp* change the event record before it is handled by the
  166.                       control panel. }
  167.                 end;
  168.  
  169.             HitCDEV:
  170.                 begin
  171.                     { If the CDEV wants to know when a control has been "hit", it can set the
  172.                       wantHit bit in the CDEV flags.  When called, data1 = Hdl to Ctl Hit &
  173.                       data2 = Ctl ID of hit control.  This message allows the CDEV to perform
  174.                       actions based on the control that was selected by the user.}
  175.  
  176.                     case loword(data2) of
  177.                         PopUp1:    ;    {popup1}
  178.                         PopUp2:    ;    {popup2}
  179.                         PopUp3:    ;    {popup3}
  180.                     end;
  181.                 end;
  182.                 
  183.             RunCDEV:
  184.                 begin
  185.                     { This message is called if the "wantRun" bit is set in the CDEV flags.  It
  186.                       enables CDEVs like time to update the display.  It is called every 60th of
  187.                       a second - every time the DARun call is issued to the control panel. -no
  188.                       parameters are passed to this routine. }
  189.                 end;
  190.  
  191.             CloseCDEV:
  192.                 begin
  193.                     { The CloseCDEV message is passed if the wantClose bit is set in the CDEV
  194.                       flags and the control panel is closing or when the user selects another
  195.                       CDEV.  During  this call data1 = windowPtr.  In general, CDEVs can do any
  196.                       memory disposal and saving of settings during this call.  The disposal
  197.                       of the CDEV's controls is handled automatically by the Control Panel. }
  198.                 end;
  199.  
  200.             ShutDownCDEV:
  201.                 begin
  202.                     { If the wantShutDown bit is set in the CDEV flags resource then
  203.                       this routine is called when the user either disables the CDEV or
  204.                       *someday* when the machine is being turned off.  It gives the CDEV
  205.                       a chance to turn itself off (or any hardware or software it controls).
  206.                       The parameters are undefined in this call. }
  207.                 end;
  208.         end;
  209.     end;
  210.  
  211. end. { CDEV unit }
  212.